#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 1e5 + 10;
typedef pair<int, int> PII;
vector<PII>res;
int n;
void merge(vector<PII>& res)
{
	sort(res.begin(), res.end());
	int st = 0, ed = -2e9;
	vector<PII>ans;
	for (int i = 0; i < n; i++) {
		if (ed < res[i].first) {
			st = res[i].first;
			ed = res[i].second;
			ans.push_back({ st,ed });
		}
		else {
			ed = max(ed, res[i].second);
		}
	}
	res = ans;
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		res.push_back({ l,r });
	}
	merge(res);
	cout << res.size() << endl;
	return 0;
}